<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>列表</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/resource/bootstrap4/css/bootstrap.css">
    <script src="${pageContext.request.contextPath}/resource/js/jquery-3.2.1.js"></script>
    <script src="${pageContext.request.contextPath}/resource/bootstrap4/js/bootstrap.js"></script>
    <script src="${pageContext.request.contextPath}/resource/My97DatePicker/WdatePicker.js"></script>
</head>
<body>
    <button type="button" onclick="location='${pageContext.request.contextPath}/desire/toInsert'">添加</button>
    <table class="table">
        <tr>
            <td>编号</td>
            <td>意象</td>
            <td>操作</td>
        </tr>
        <c:forEach items="${list}" var="d">
            <tr>
                <td>${d.id}</td>
                <td>${d.name}</td>
                <td>
                    <a onclick="location='${pageContext.request.contextPath}/desire/toUpdate?id=${d.id}'">修改</a>
                    <a onclick="del(${d.id})">删除</a>
                </td>
            </tr>
        </c:forEach>
    </table>
    <script>
        function del(id) {
            $.post("${pageContext.request.contextPath}/desire/delete",{"id":id},function (result) {
                if (result > 0){
                    alert("删除成功");
                    location.reload();
                }else{
                    alert("删除失败");
                }
            })
        }
    </script>
</body>
</html>
